<%--
  - Author		:	Jaewon Choi
  --%>
<%@ page language="java" %>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/pages/includes/taglibs.jspf" %>
<%@ include file="/WEB-INF/pages/includes/variables.jspf" %>
<%@ include file="/WEB-INF/pages/includes/doctype.jspf" %>
<c:choose>
	<c:when test="${not empty urgencyNotice}">
		<c:set var="fAct" value="수정" />
	</c:when>
	<c:otherwise>
		<c:set var="fAct" value="등록" />
	</c:otherwise>
</c:choose>
<html>
	<head>
<%@ include file="/WEB-INF/pages/includes/metatags.jspf" %>
		<title><fmt:message key="pages.title" /></title>
		<link rel="stylesheet" type="text/css" href="<c:url value="${dirStyles}/common.css" />" />

		<link rel="stylesheet" type="text/css" href="<c:url value="${dirScripts}/jqueryUi/css/ui-lightness/jquery-ui-1.8.21.custom.css" />" />

		<script type="text/javascript" src="<c:url value="${dirScripts}/jquery-1.7.2.min.js" />"></script>
		<script type="text/javascript" src="<c:url value="${dirScripts}/jquery-ui-1.8.21.custom.min.js" />"></script>
		<script type="text/javascript">
			$(function(){
				$("#name").focus();
				
				$( ".date" ).datepicker({
					showOn: "both",
					buttonImage: "<c:url value="${dirImages}/calendar.png" />",
					buttonImageOnly: true,
					dateFormat: "yy-mm-dd",
					showWeek: true
				});
			});			

			function validation(){
				<c:if test="${param.fAct eq 'view'}">
					return true;
				</c:if>
				try{
					if($(".categoryIdx option:selected").val().replace(/\s/g, '') == "") {
						alert("[브랜드]은 필수 선택 항목입니다.");
						document.frm.categoryIdx.focus();
						return false;
					}
					
					if((document.frm.name.value).replace(/\s/g, '') == ""){
						alert("[제목]은 필수 입력 항목입니다.");
						document.frm.name.focus();
						return false;
					}					


					<c:if test="${empty urgencyNotice}">
						if((document.frm.urgencyNoticeFile.value).replace(/\s/g, '') == ""){
							alert("[내용]는 필수 입력 항목입니다.");
							document.frm.urgencyNoticeFile.focus();
							return false;
						}
						/*
						if((document.frm.urgencyNoticeFile2.value).replace(/\s/g, '') == ""){
							alert("[내용]는 필수 입력 항목입니다.");
							document.frm.urgencyNoticeFile2.focus();
							return false;
						}
						if((document.frm.urgencyNoticeFile3.value).replace(/\s/g, '') == ""){
							alert("[내용]는 필수 입력 항목입니다.");
							document.frm.urgencyNoticeFile3.focus();
							return false;
						}
						if((document.frm.urgencyNoticeFile4.value).replace(/\s/g, '') == ""){
							alert("[내용]는 필수 입력 항목입니다.");
							document.frm.urgencyNoticeFile4.focus();
							return false;
						}
						*/
					</c:if>	

				}catch(err){
					return false;	
				}
				
				return confirm("${fAct} 하시겠습니까?");
			}
		</script>
	</head>
	<body>
		<div class="bodyWrap">
<%@ include file="/WEB-INF/pages/includes/header.jsp" %>
<%@ include file="/WEB-INF/pages/includes/left.jsp" %>
			<div class="contWrap">
				<div class="menuTitle">
					긴급공지 ${fAct}
				</div>
				<form id="frm" name="frm" method="post" enctype="multipart/form-data" action="<c:url value="/urgencyNotice/submit.do" />" onsubmit="return validation();">
					<input type="hidden" name="maxnum" value="${param.maxnum}" />
					<input type="hidden" name="page" value="${param.page}" />
					<input type="hidden" name="searchDate" value="${param.searchDate}">
					<input type="hidden" name="startDate" value="${param.startDate}" /> 
					<input type="hidden" name="endDate" value="${param.endDate}" />
					<input type="hidden" name="searchName" value="${param.searchName}" />
					
					<table class="frmTbl">
						<colgroup>
							<col width="176px;" />
							<col width="*" />
							<col width="100px;" />
							<col width="*" />
						</colgroup>
						<tbody>
			 				<c:if test="${not empty urgencyNotice}">
			 					<tr>
									<th>긴급공지 IDX</th>
									<td colspan="2">
										${urgencyNotice.idx}
										<input type="hidden" name="idx" value="${urgencyNotice.idx}">
									</td>
								</tr>
			 				</c:if>
			 				<tr>
								<th>브랜드 *</th>
								<td>
									<select class="categoryIdx" name="categoryIdx">
										<option value="">선택</option>
										<c:forEach var="category" items="${categoryList}">
											<option value="${category.idx}" <c:if test="${urgencyNotice.categoryIdx eq category.idx}"> selected="selected" </c:if>>${category.name}</option>
										</c:forEach>
									</select>
								</td>
							</tr>
			 				<tr>
								<th>기간</th>
								<td colspan="2">
									<label>
										<input type="checkbox" <c:if test="${empty urgencyNotice.beginTime && empty urgencyNotice.endTime}"> checked="checked" </c:if> onclick="javascript:if(this.checked){$('.date').attr('disabled','disabled');}else{$('.date').removeAttr('disabled');};"> 항상
									</label>
									<c:catch var="e">
										<fmt:parseDate var="beginTime" pattern="yyyy-MM-dd HH:mm:ss" value="${urgencyNotice.beginTime}" />
										<fmt:formatDate var="beginTime" value="${beginTime}" pattern="yyyy-MM-dd" />
									</c:catch>
									<c:if test="${not empty e}">
										<c:set var="beginTime" value="${urgencyNotice.beginTime}" />
									</c:if>
									<c:catch var="e">
										<fmt:parseDate var="endTime" pattern="yyyy-MM-dd HH:mm:ss" value="${urgencyNotice.endTime}" />
										<fmt:formatDate var="endTime" value="${endTime}" pattern="yyyy-MM-dd" />
									</c:catch>
									<c:if test="${not empty e}">
										<c:set var="endTime" value="${urgencyNotice.endTime}" />
									</c:if>
									<input type="text" class="date" name="beginTime" <c:if test="${empty urgencyNotice.beginTime && empty urgencyNotice.endTime}"> disabled="disabled" </c:if> readonly="readonly" value="${beginTime}" />
									~
									<input type="text" class="date" name="endTime" <c:if test="${empty urgencyNotice.beginTime && empty urgencyNotice.endTime}"> disabled="disabled" </c:if> readonly="readonly" value="${endTime}" />
								</td>
							</tr>
							<tr>
								<th>제목 *</th>
								<td colspan="2">
									<input type="text" id="name" name="name" value="${urgencyNotice.name}" style="width: 600px;" maxlength="50" title="제목 입니다." />
								</td>
							</tr>
							<input type="hidden" name="emblem" value="X" />							
							<tr>
								<th>내용 *</th>
								<td colspan="2">
									<input type="file" id="urgencyNoticeFile" name="urgencyNoticeFiles[0]" />
									<input type="hidden" name="urgencyNoticeFileTypes" value="urgencyNoticeImg" />
									<input type="hidden" name="urgencyNoticeFileDatas" value="" />
									<c:if test="${not empty urgencyNoticeImg[0].fileUrl}">
										<br /><img src="${urgencyNoticeImg[0].fileUrl}" class="thumbnailImg" />
									</c:if>
								</td>
							</tr>
							<input type="hidden" name="urgencyNoticeFileTypes" value="urgencyNoticeImg2" />
							<input type="hidden" name="urgencyNoticeFileDatas" value="" />
							<!-- 
							<tr>								
								<td colspan="2">
									<input type="file" id="urgencyNoticeFile2" name="urgencyNoticeFiles[1]" /> 800*1280
									<input type="hidden" name="urgencyNoticeFileTypes" value="urgencyNoticeImg2" />
									<input type="hidden" name="urgencyNoticeFileDatas" value="" />
									<c:if test="${not empty urgencyNoticeImg2[0].fileUrl}">
										<br /><img src="${urgencyNoticeImg2[0].fileUrl}" class="thumbnailImg" />
									</c:if>
								</td>
							</tr>
							<tr>
								<td colspan="2">
									<input type="file" id="urgencyNoticeFile3" name="urgencyNoticeFiles[2]" /> 1080*1960
									<input type="hidden" name="urgencyNoticeFileTypes" value="urgencyNoticeImg3" />
									<input type="hidden" name="urgencyNoticeFileDatas" value="" />
									<c:if test="${not empty urgencyNoticeImg3[0].fileUrl}">
										<br /><img src="${urgencyNoticeImg3[0].fileUrl}" class="thumbnailImg" />
									</c:if>
								</td>
							</tr>
							<tr>
								<td colspan="2">
									<input type="file" id="urgencyNoticeFile4" name="urgencyNoticeFiles[3]" /> 640*960
									<input type="hidden" name="urgencyNoticeFileTypes" value="urgencyNoticeImg4" />
									<input type="hidden" name="urgencyNoticeFileDatas" value="" />
									<c:if test="${not empty urgencyNoticeImg4[0].fileUrl}">
										<br /><img src="${urgencyNoticeImg4[0].fileUrl}" class="thumbnailImg" />
									</c:if>
								</td>
							</tr>							
							 -->
							 <tr>
								<th>링크</th>
								<td colspan="2">									
										<input type="text" name="url" style="width: 500px;" value="${urgencyNotice.url}"  />
								</td>
							</tr>
							 <tr>
								<th>URL 타입</th>
								<td colspan="2">
									<label>
										<input type="radio" name="urlType" class="urlType" value="01" <c:if test="${urgencyNotice.urlType eq '01'}"> checked="checked" </c:if>> 내부
									</label>			
									<label>
										<input type="radio" name="urlType" class="urlType" value="02" <c:if test="${empty urgencyNotice || urgencyNotice.urlType eq '02'}"> checked="checked" </c:if> > 외부
									</label>
								</td>
							</tr>
							<tr>
								<th>노출 여부</th>
								<td colspan="2">
									<label>
										<input type="radio" name="isMain" value="1" <c:if test="${empty urgencyNotice or urgencyNotice.isMain eq 1}"> checked="checked" </c:if> /> Yes
										
									</label>
									<label>
										<input type="radio" name="isMain" value="0" <c:if test="${urgencyNotice.isMain eq 0}"> checked="checked" </c:if> /> No
									</label>
								</td>
							</tr>				
						</tbody>
					</table>	
					<input type="button" class="btn" value="취소" onclick="javascript:document.listFrm.submit();" />
					<input type="submit" class="btn" value="${fAct}" />
					<c:if test="${not empty advertising}">
						<input type="button" class="btn" value="삭제" onclick="javascript:if(confirm('삭제 하시겠습니까?')){document.removeFrm.submit();}" />
					</c:if>
				</form>
				<form name="listFrm" action="<c:url value="/urgencyNotice/list.do" />" method="post" style="display: none;">
					<input type="hidden" name="maxnum" value="${param.maxnum}" />
					<input type="hidden" name="page" value="${param.page}" />
					<input type="hidden" name="searchDate" value="${param.searchDate}">
					<input type="hidden" name="startDate" value="${param.startDate}" /> 
					<input type="hidden" name="endDate" value="${param.endDate}" />
					<input type="hidden" name="name" value="${param.searchName}" />
				</form>
				
				<form name="removeFrm" action="<c:url value="/urgencyNotice/remove.do" />" method="post" style="display: none;">
					<input type="hidden" name="fAct" value="remove">
					<input type="hidden" name="idx" value="${urgencyNotice.idx}">
					<input type="hidden" name="maxnum" value="${param.maxnum}" />
					<input type="hidden" name="page" value="${param.page}" />
					<input type="hidden" name="searchDate" value="${param.searchDate}">
					<input type="hidden" name="startDate" value="${param.startDate}" /> 
					<input type="hidden" name="endDate" value="${param.endDate}" />
					<input type="hidden" name="searchName" value="${param.searchName}" />
				</form>
			</div>
<%@ include file="/WEB-INF/pages/includes/footer.jsp" %>
		</div>
	</body>
</html> 